<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>RVM : Debugging the RVM</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">	    
    </head>

    <body>
	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
		    <tr>
			    <td valign="top" class="pagebody">
				    <div class="pageheader">
					    <span class="pagetitle">
                            RVM : Debugging the RVM
                                                    </span>
				    </div>
				    <div class="pagesubheading">
					    This page last changed on Oct 23, 2009 by <font color="#0050B2">l.hellyer@kent.ac.uk</font>.
				    </div>

				    <p>There are different tools for debugging Jikes RVM:</p>

<h2><a name="DebuggingtheRVM-GDB"></a>GDB</h2>

<p>There is a limited amount of C code used to start Jikes RVM. The rvm script will start Jikes RVM using GDB (the GNU debugger) if the first argument is <tt>&#45;gdb</tt>. Break points can be set in the C code, variables, registers can be expected in the C code.</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>rvm -gdb &lt;RVM args&gt; &lt;name of Java application&gt; &lt;application args&gt;
</pre>
</div></div>
<p>The dynamically created Java code doesn't provide GDB with the necessary symbol information for debugging. As some of the Java code is created in the boot image, it is possible to find the location of some Java methods and to break upon them. To determine the location use the RVM.map file. A script to enable use of the RVM.map as debugger information inside GDB is provided <a href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1160674&amp;group_id=128805&amp;atid=723235">here</a>.</p>

<p>Details of how to manually walk the stack in GDB can be found <a href="GDB Stack Walking.html" title="GDB Stack Walking">here</a></p>

<h2><a name="DebuggingtheRVM-OtherTools"></a>Other Tools</h2>

<p>Other tools, such as valgrind, are occasionally useful in debugging or understanding the behaviour of JikesRVM.&nbsp; The rvm script facilitates using these tools with the '-wrap' argument.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
rvm -wrap <span class="code-quote">"&lt;wrapper-script-and-args&gt;"</span> &lt;<span class="code-keyword">rest</span> of command line&gt;
</pre>
</div></div>
<p>For example, cachegrind can be invoked by</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
rvm -wrap <span class="code-quote">"/path/to/valgrind --tool=cachegrind"</span> &lt;java-command-line&gt;
</pre>
</div></div>
<p>The command and arguments immediately after the &#45;wrap argument will be inserted into the script on the command line that invokes the boot image runner.&nbsp; One useful variant is<br class="atl-forced-newline" /></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
rvm -wrap echo &lt;<span class="code-keyword">rest</span> of command line&gt;
</pre>
</div></div>

<h2><a name="DebuggingtheRVM-DebuggerThread"></a>Debugger Thread</h2>

<p>Jikes has an interactive debugger that you can invoke by  sending SIGQUIT to Jikes while it's running:</p>

<p>pkill &#45;SIGQUIT JikesRVM</p>

<p>In previous versions of Jikes, that stopped all threads and provided an interactive prompt, but currently it just dumps the state of the VM and continues immediately (that's a known issue: <a href="http://jira.codehaus.org/browse/RVM-570">http://jira.codehaus.org/browse/RVM-570</a>).</p>


<h2><a name="DebuggingtheRVM-%26nbsp%3BJavaPlatformDebuggerArchitecture%28JPDA%29"></a>&nbsp;<a href="http://java.sun.com/j2se/1.5.0/docs/guide/jpda/index.html">Java Platform Debugger Architecture (JPDA)</a></h2>

<p>In general the JPDA provides 3 mechanisms for debugging Java applications:</p>
<ul>
	<li>The <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jpda/jdi/index.html">Java Debug Interface</a> is an API for debugging Java code from Java.</li>
	<li>The <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html">JVM Tools Interface</a> is an API for writing native/C code for debugging a JVM, it is similar to the Java Native Interface (JNI).</li>
	<li>The <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jpda/jdwp-spec.html">Java Debug Wire Protocol</a> is a network protocol for debugging Java code running on JVMs.</li>
</ul>


<p>Currently JDWP code is being implemented in Jikes RVM based on the GNU Classpath implementation.</p>

				    
                                            <div class="tabletitle">
                            <a name="comments">Comments:</a>
                        </div>

                        <table border="0" width="100%">
                                                        <tr>
                                <td >
                                    <a name="comment-143818754"></a>
                                    <font class="smallfont"><p>A heuristic method:</p>

<p>1. use Log file to print out object header, so you can trace where these object come from, and details of its lifecycle</p>

<p>2. use Magic or ObjectReference and instanceof or something else to print out object address, which is, the target objects you want to analyse</p>

<p>3. use grep or perl to grab text from the huge log file obtained by set &#45;X:gc:verbose=11 &#45;X:sysLogfile=xx.txt &#45;X:gc:sanityCheck=true</p></font>
                                    <div align="left" class="smallfont" style="color: #666666; width: 98%; margin-bottom: 10px;">
                                        <img src="images/icons/comment_16.gif" height="16" width="16" border="0" align="absmiddle"/>
                                        Posted by vondart at Mar 27, 2010 20:23
                                    </div>
                                </td>
                            </tr>
                                                    </table>
                    			    </td>
		    </tr>
	    </table>
	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td height="12" background="http://docs.codehaus.org/images/border/border_bottom.gif"><img src="images/border/spacer.gif" width="1" height="1" border="0"/></td>
			</tr>
		    <tr>
			    <td align="center"><font color="grey">Document generated by Confluence on Jul 04, 2010 19:57</font></td>
		    </tr>
	    </table>
    </body>
</html>